package com.softeem.music_sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softeem.music_sys.comm.Result;
import com.softeem.music_sys.entity.Singer;
import com.softeem.music_sys.service.SingerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 歌手控制器
 */
@Tag(name = "歌手接口", description = "歌手相关操作:添加、查询、修改、删除等")
@RestController
@RequestMapping("/singer")
public class SingerController {
    
    @Autowired
    private SingerService singerService;

    @Operation(summary = "添加歌手", description = "添加新歌手信息")
    @PostMapping
    public Result add(@RequestBody Singer singer) {
        return singerService.addSinger(singer);
    }

    @Operation(summary = "获取歌手信息", description = "根据ID获取歌手详细信息")
    @GetMapping("/{id}")
    public Result getSingerById(@PathVariable Integer id) {
        return singerService.getSingerById(id);
    }

    @Operation(summary = "更新歌手信息", description = "更新歌手信息")
    @PutMapping
    public Result update(@RequestBody Singer singer) {
        return singerService.updateSinger(singer);
    }

    @Operation(summary = "删除歌手", description = "根据ID删除歌手")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        return singerService.deleteSinger(id);
    }

    @Operation(summary = "获取歌手列表", description = "分页获取歌手列表")
    @Parameters({
            @Parameter(name = "page", description = "页码"),
            @Parameter(name = "limit", description = "每页数量")
    })
    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                      @RequestParam(defaultValue = "10") Integer limit) {
        Page<Singer> resultPage = singerService.getSingerList(page, limit);
        return Result.success().setData(resultPage);
    }

    @Operation(summary = "搜索歌手", description = "根据歌手名搜索")
    @GetMapping("/search")
    public Result search(@RequestParam String name,
                        @RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer limit) {
        Page<Singer> resultPage = singerService.searchSingers(name, page, limit);
        return Result.success().setData(resultPage);
    }

    @Operation(summary = "按类型获取歌手", description = "根据歌手类型获取列表")
    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable String type,
                           @RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "10") Integer limit) {
        Page<Singer> resultPage = singerService.getSingersByType(type, page, limit);
        return Result.success().setData(resultPage);
    }

    @Operation(summary = "按标签获取歌手", description = "根据音乐风格标签获取歌手")
    @GetMapping("/tag")
    public Result getByTag(@RequestParam String tag,
                          @RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer limit) {
        Page<Singer> resultPage = singerService.getSingersByTag(tag, page, limit);
        return Result.success().setData(resultPage);
    }

    @Operation(summary = "修改歌手状态", description = "上架/下架歌手")
    @Parameters({
            @Parameter(name = "id", description = "歌手ID"),
            @Parameter(name = "status", description = "状态 1-上架 0-下架")
    })
    @PutMapping("/status/{id}")
    public Result updateStatus(@PathVariable Integer id, @RequestParam Integer status) {
        return singerService.updateSingerStatus(id, status);
    }
}